#pragma once

#include <ppapi/cpp/dev/scriptable_object_deprecated.h>

#include <map>
#include <vector>
#include <string>

namespace raytrace {

class Raytrace;

class RaytraceScriptObject : public pp::deprecated::ScriptableObject {
 public:
  explicit RaytraceScriptObject(Raytrace* app_instance);
  virtual ~RaytraceScriptObject() {}
    
  virtual bool HasMethod(const pp::Var& method, pp::Var* exception);
  virtual bool HasProperty(const pp::Var& property, pp::Var* exception);

  virtual pp::Var Call(const pp::Var& method,
                       const std::vector<pp::Var>& args,
                       pp::Var* exception);

  virtual void SetProperty(const pp::Var& property,
                           const pp::Var& value,
                           pp::Var* exception);
  virtual pp::Var GetProperty(const pp::Var& property,
                              pp::Var* exception);

  typedef pp::Var (Raytrace::*MethodFunc)(void);
  void RegisterMethod(const std::string& method_name,
                      MethodFunc method);

  typedef bool (Raytrace::*SetPropertyFunc)(const pp::Var& value);
  typedef bool (Raytrace::*GetPropertyFunc)(pp::Var& value);
  void RegisterProperty(const std::string& property_name,
                        GetPropertyFunc get_property,
                        SetPropertyFunc set_property);

 private:
  Raytrace* app_instance_;
  std::map<std::string, MethodFunc> method_map_;
  std::map<std::string,
           std::pair<GetPropertyFunc, SetPropertyFunc> > property_map_;
};
}
